package com.bdc.whatwhat.views.cell;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bdc.whatwhat.R;
import com.bdc.whatwhat.modele.WhatWhat;
import com.bdc.whatwhat.modele.Whatter;
import com.bdc.whatwhat.utils.ImageUtils;
import com.bdc.whatwhat.utils.NumberUtils;
import com.bdc.whatwhat.views.ProgressCircleXp;

import org.w3c.dom.Text;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by gfimac on 21/07/2014.
 */
public class HeaderCell extends ViewCell<Whatter> implements View.OnClickListener {

    ProgressCircleXp progressCircleXp;
    TextView nombre;
    TextView texte;

    View cercleRouge;

    TextView niveau;
    TextView experience;
    View share;

    @Override
    public void animer() {
        progressCircleXp.animer();
    }

    @Override
    public void construire() {
        NumberUtils.tester();
    }

    @Override
    public void charger() {
        progressCircleXp = (ProgressCircleXp) findViewById(R.id.progress_circle_xp);
        nombre = (TextView) findViewById(R.id.whatwhat_nombre);
        texte = (TextView) findViewById(R.id.whatwhat_texte);

        niveau = (TextView) findViewById(R.id.niveau);
        experience = (TextView) findViewById(R.id.experience);
        share = findViewById(R.id.share);

        cercleRouge = findViewById(R.id.cercle_rouge);
    }

    @Override
    public void remplir() {
        if (getObject() != null) {


            //1. Le WhatWhat
            WhatWhat whatWhat = getObject().getWhatWhat();

            if (whatWhat != null) {
                findViewById(R.id.relative_nombre_personne).setVisibility(View.VISIBLE);
                findViewById(R.id.progress_load).setVisibility(View.GONE);
                if (whatWhat.getTexte() != null) {
                    String output = whatWhat.getTexte().substring(0, 1).toUpperCase() + whatWhat.getTexte().substring(1);
                    texte.setText("“" + output + "”");
                }
                if (whatWhat.getNombre() != null)
                    nombre.setText(NumberUtils.format(whatWhat.getNombre()));
            }

            //2. L'experience
            if (getObject().getNiveau() != null)
                niveau.setText("Niveau " + getObject().getNiveau());

            if (getObject().getXpActuel() != null && getObject().getXpMax() != null) {
                experience.setText(getObject().getXpActuel() + "/" + getObject().getXpMax());
            }
            progressCircleXp.setPourcentage(getObject().getXpPourcentage());
        }
    }

    @Override
    public void ajouterListeners() {
        share.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        ImageUtils.sendImageShare(getContext(),getView());
    }

}
